package jfprincesstests.fakes.automata;

import jfuzzyprincepless.zarchive.FSM.INode;
import jfuzzyprincepless.zarchive.FSM.IOutcome;
import jfuzzyprincepless.zarchive.FSM.Node;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class FakeNode extends Node {
	private final StringBuilder sb;
	private int pos = 0;

	public FakeNode(String name, StringBuilder sb) {
		super(name);
		this.sb = sb;
	}

	@Override
	public IOutcome chooseOutcome(
			INegotiationContext context
	) {
		IOutcome result = getOutcomes().get(
			pos++ % getOutcomes().size()
		);
		sb.append(";choose[").append(this).append("]");
		return result;
	}

	public void setNext(INode ... nodes) {
		getOutcomes().clear();
		for (INode node : nodes) {
			getOutcomes().add(new FakeOutcome(node, sb));
		}
	}

	@Override
	public String toString() {
		return getName();
	}
}
